<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="../js/jquery.js">
        </script>
        <link type="text/css" rel="stylesheet" href="style.css" />
        <title>YHang Movie Admin Panel</title>
    </head>
    <body>
<?php
function strget($str, $str_start, $str_end, $str_offset = '') {
	$str = $str_offset ? substr($str, strpos($str, $str_offset)) : $str;
	$pos_start = strpos($str, $str_start) + strlen($str_start);
//	echo $pos_start."|";
	$pos_end = strpos($str, $str_end, $pos_start);
//	echo $pos_end."|";
	return substr($str, $pos_start, $pos_end - $pos_start);
}

$id = isset($_GET['id']) ? $_GET['id'] : 43122;
$url = "http://data.movie.xunlei.com/movie/$id";
$code = file_get_contents($url);
$movie_intro = strget($code, '<p>', '<a target="_blank"','<h3>剧情简介</h3>');
$code = strget($code, '<div class="moviePic">', '<div class="movieScore');
//get image and name
$matches_name = array();
preg_match_all('/<img id="img_movie_120x168" src="(.*)" alt="(.*)" \/>/i',$code,$matches_name,PREG_SET_ORDER);
//print_r($matches_name);
echo "<h1>{$matches_name[0][2]}</h1>\n";
echo "<img src='{$matches_name[0][1]}' />\n";
//get director
$code_director = strget($code,'<p><strong>导演: </strong>','<p><strong>主演: </strong>');
$matches_director = array();
preg_match_all('/href="person\/(.*?)"(.*)>(.*)<\/a>/i',$code_director,$matches_director,PREG_SET_ORDER);
echo "<li>导演：";
foreach ($matches_director as $val) {
	echo $val[3].$val[1].' ';
}
echo "</li>\n";
//print_r($matches_director);
//get player
$code_player = strget($code,'<p><strong>主演: </strong>','<p><strong>制片国家/地区: </strong>');
$matches_player = array();
preg_match_all('/href="person\/(.*?)"(.*?)>(.*?)<\/a>/i',$code_player,$matches_player,PREG_SET_ORDER);
//print_r($matches_player);
foreach ($matches_player as $val) {
	echo "<li>".$val[3].$val[1]."</li>\n";
}
$movie_area = strget($code, '<p><strong>制片国家/地区: </strong><a target="_blank" href="type,area/movie,','">');
echo "<li>area:$movie_area</li>\n";
$movie_genre = strget($code, "<p><strong>类型: </strong><a  target='_blank' href='type,genre/movie,","'>");
echo "<li>area:$movie_genre</li>\n";
echo "<li>$movie_intro</li>";
echo "<li><textarea cols='100' rows='20'>$code</textarea></li>";
?>
</body>
</html>